#import Mods

import wsgiref.handlers
import cgi
import os
import urllib
import webob
import Fetch
import Auth
import Mods
from google.appengine.api.urlfetch import fetch
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.api import datastore
from google.appengine.api import datastore_types

class Story(db.Model):
  title = db.StringProperty()
  body = db.TextProperty()



class MainHandler(webapp.RequestHandler):
  def get(self):

    
    user = users.get_current_user()
    if self.request.get("action") == "logout":
      self.redirect(users.create_logout_url("/login/"))
      return
    if user:
      self.response.out.write("""<html>
                              <head>
                              <meta http-equiv="REFRESH" content="2;url=/..">
                              </head>
                              <body>
                              
                              Hello, """ + user.nickname() + """
               
                              </body></html>
                              """
                              )
    else:
      self.redirect(users.create_login_url(self.request.uri))

    

    
def main():
  application = webapp.WSGIApplication([('/login/', MainHandler)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()